package org.qb.mapreduce.rewritePartioner;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FlowDriver {
    public static void main(String[] args) throws InterruptedException, ClassNotFoundException, IOException {

        //1 获取job
        Configuration configuration = new Configuration();

        Job job = getJob(configuration);


        //设置数据输入路径和输出路径
        FileInputFormat.setInputPaths(job,new Path("D:\\big data\\hadoop3.X\\资料\\11_input\\inputflow"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\big data\\hadoop3.X\\output\\rewirtePartionerDemo1"));


        //提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }

    private static  Job getJob(Configuration configuration) throws IOException {
        Job job = Job.getInstance(configuration);

        //设置jar
        job.setJarByClass(FlowDriver.class);

        //关联mapper reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);

        //设置mapper 输出的key value 类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);


        //设置 mapper 最终输出key value 类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        //设置partioner 类
        job.setPartitionerClass(ProvincePartioner.class);

        //设置numRuduce为5，因为我们指定5份文件==>
        // 只有大于1的才会走HashPatitioner，我们上面重写才有效
        job.setNumReduceTasks(5);

        return job;
    }
}
